package com.hzlj.position.job.job;

import com.fz.common.redis.annotation.SyncLock;
import com.hzlj.position.locate.service.MessageTodayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class MessageTodayJob {
    @Resource
    private MessageTodayService messageTodayService;


    /**
     * 每隔2分别一次
     */
    @SyncLock(lockMs = 60000)
    @Scheduled(cron = "${job.message.notice:0 0/1 * * * ?}")
    public void send() {
        long start = System.currentTimeMillis();
        log.info("任务开始执行[发送消息]");
        int size = messageTodayService.send();
        log.info("任务结束执行[发送消息],cost={},size={}", System.currentTimeMillis() - start, size);
    }

    /**
     * 凌晨执行
     */
    @SyncLock(lockMs = 60000)
    @Scheduled(cron = "${job.message.delete:0 0 0 * * ?}")
    public void delete() {
        long start = System.currentTimeMillis();
        log.info("任务开始执行[删除消息]");
        messageTodayService.delete();
        log.info("任务结束执行[删除消息],cost={}", System.currentTimeMillis() - start);
    }

}
